535. Encode and Decode TinyURL
Note: This is a companion problem to the System Design problem: Design TinyURL.

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.

There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

Implement the Solution class:

  • Solution() Initializes the object of the system.
  • String encode(String longUrl) Returns a tiny URL for the given longUrl.
  • String decode(String shortUrl) Returns the original long URL for the given shortUrl. It is guaranteed that the given shortUrl was encoded by the same object.

 

Example 1:

Input: url = "https://leetcode.com/problems/design-tinyurl"
Output: "https://leetcode.com/problems/design-tinyurl"

Explanation:
Solution obj = new Solution();
string tiny = obj.encode(url); // returns the encoded tiny url.
string ans = obj.decode(tiny); // returns the original url after deconding it.

 

Constraints:

  • 1 <= url.length <= 104
  • url is guranteed to be a valid URL.
#1 Two Sum
Easy
#2 Add Two Numbers
Medium
#3 Longest Substring Without Repeating Characters
Medium
#4 Median of Two Sorted Arrays
Hard
#5 Longest Palindromic Substring
Medium
#6 Zigzag Conversion
Medium
#7 Reverse Integer
Medium
#8 String to Integer (atoi)
Medium
#9 Palindrome Number
Easy
#10 Regular Expression Matching
Hard
#11 Container With Most Water
Medium
#12 Integer to Roman
Medium
#13 Roman to Integer
Easy
#14 Longest Common Prefix
Easy
#15 3Sum
Medium
#16 3Sum Closest
Medium
#17 Letter Combinations of a Phone Number
Medium
#18 4Sum
Medium
#19 Remove Nth Node From End of List
Medium
#20 Valid Parentheses
Easy
#21 Merge Two Sorted Lists
Easy
#22 Generate Parentheses
Medium
#23 Merge k Sorted Lists
Hard
#24 Swap Nodes in Pairs
Medium
#25 Reverse Nodes in k-Group
Hard
#26 Remove Duplicates from Sorted Array
Easy
#27 Remove Element
Easy
#28 Find the Index of the First Occurrence in a String
Medium
#29 Divide Two Integers
Medium
#30 Substring with Concatenation of All Words
Hard
#31 Next Permutation
Medium
#32 Longest Valid Parentheses
Hard
#33 Search in Rotated Sorted Array
Medium
#34 Find First and Last Position of Element in Sorted Array
Medium
#35 Search Insert Position
Easy
#36 Valid Sudoku
Medium
#37 Sudoku Solver
Hard
#38 Count and Say
Medium
#39 Combination Sum
Medium
#40 Combination Sum II
Medium
#41 First Missing Positive
Hard
#42 Trapping Rain Water
Hard
#43 Multiply Strings
Medium
#44 Wildcard Matching
Hard
#45 Jump Game II
Medium
#46 Permutations
Medium
#47 Permutations II
Medium
#48 Rotate Image
Medium
#49 Group Anagrams
Medium
#50 Pow(x, n)
Medium